$(function(){
	var walletType=sessionStorage.getItem("walletType");
	var logonToken=sessionStorage.getItem("logonToken");
	var playId=sessionStorage.getItem("playId");
	
//	获取数据
 	var json = {
        "logonToken": logonToken,
        "walletType": walletType,
        "playId":playId
    }
	$.ajax({
		type:"post",
		url:url + '/bigWinner/api/withdrawRecord/withdrawRecordPage',
		data:JSON.stringify(json),
		dataType:'json',
		contentType: "application/json;charset=UTF-8",
		success:function(result){
			if(result.success){
				$(".balance").val(result.obj.balance);
				$(".rate").val(result.obj.rate);
			}else{
				isErr(result);
			}
		},
		error:function (XMLHttpRequest, textStatus, errorThrown) { 
			alert("请求失败："+XMLHttpRequest.status);     
		}
	});
	
	
//	输入提币数量
	$(".withdrawNum").on("change",function(){
		var withdrawNum=$(".withdrawNum").val();
		var balance=$(".balance").val();
		var rate=$(".rate").val();
		if(!withdrawNum){
			alert("请输入提币数量");
			$(".qr_btn").attr("disabled",false);
			return false;
		}
		var json = {
	        "logonToken": logonToken,
	        "walletType": walletType,
	        "playId":playId,
	        "balance":balance,
	        "rate":rate,
	        "withdrawNum":withdrawNum
	    }
		$.ajax({
			type:"post",
			url:url + '/bigWinner/api/withdrawRecord/currencyWithdraw',
			data:JSON.stringify(json),
			dataType:'json',
			contentType: "application/json;charset=UTF-8",
			success:function(result){
				if(result.success){
					$(".estimatedNum").val(result.obj.estimatedNum);
					$(".qr_btn").attr("disabled",false);
				}else{
					isErr(result);
					$(".qr_btn").attr("disabled",true);
				}
			},
			error:function (XMLHttpRequest, textStatus, errorThrown) { 
				alert("请求失败："+XMLHttpRequest.status);     
			}
		});
	})
	
//	重置
	$(".cz_btn").on("click",function(){
		$(".withdrawNum").val("");
		$(".estimatedNum").val("");
	})
	
	
//	提币提交
	$(".qr_btn").on("click",function(){
		var withdrawNum=$(".withdrawNum").val();
		var balance=$(".balance").val();
		if(!withdrawNum){
			alert("请输入提币数量");
			return false;
		}
		if(Number(withdrawNum) > Number(balance)){
			alert("提币数量不能大于余额数量");
			return false;
		}
		$("#exampleModal").modal("toggle");
	})
	
//	提交
	var prevent_repetition = true;
	$(".money_btn").on("click",function(){
		if (prevent_repetition) {
            prevent_repetition = false;
            var withdrawNum=$(".withdrawNum").val();
			var balance=$(".balance").val();
			var rate=$(".rate").val();
			var payPassword = $("#recipient-name1").val();
			if(!payPassword){
				alert("请输入支付密码");
				prevent_repetition = true;
				return false;
			}
			var json = {
		        "logonToken": logonToken,
		        "walletType": walletType,
		        "playId":playId,
		        "balance":balance,
		        "rate":rate,
		        "withdrawNum":withdrawNum,
		        "payPassword":payPassword
		    }
			$.ajax({
                type: "post",
                url: url + '/bigWinner/api/withdrawRecord/withdraw',
                data: JSON.stringify(json),
                dataType: 'json',
                contentType: "application/json",
                success: function(result) {
                    if (result.success) {
                       	alert(result.msg);
                       	
//                     	修改余额
						var ll=Number($(".balance").val())-Number(withdrawNum);
						$(".balance").val(ll);
						sessionStorage.setItem("available_balance",ll);
                       	
                        $("#exampleModal").modal("toggle");
//                      初始化提币记录
						$(".load_more").html("加载更多....");
						$(".modal_list").html("");
						page = 1;
						mentionMoney_list(page);
                                                window.location.reload();
                    } else {
                        isErr(result);
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                   alert("请求失败："+XMLHttpRequest.status);
                },
                complete: function() {
                    prevent_repetition = true;
                }
            });
		}
	})
	
	var page=1;
	rows=10;
	
//	充币记录
	function mentionMoney_list(page){
		var json1 = {
	        "logonToken": logonToken,
	        "walletType": walletType,
	        "playId":playId,
	        "page":page,
	        "rows":rows
	  	}
		$.ajax({
			type:"post",
			url:url + '/bigWinner/api/withdrawRecord/withdrawRecord',
			data:JSON.stringify(json1),
			dataType:'json',
			contentType: "application/json;charset=UTF-8",
			success:function(result){
				if(result.success){
					var html='';
					var data=result.obj.withdrawRecordList;
					for(var i in data){
						html += '<div class="modal_charge_record">';
	                    html += '<p>ID<span>'+data[i].id+'</span></p>';
	                    if(data[i].type == "1"){
	                    	html += '<p>币种<span>ETH</span></p>';
	                    }else{
	                    	html += '<p>币种<span>BTC</span></p>';
	                    }
	                    html += '<p>提币数量<span>'+data[i].num+'</span></p>';
	                    html += '<p>实际数量<span>'+data[i].trueNum+'</span></p>';
	                    html += '<p>申请时间<span>'+data[i].addTime+'</span></p>';
	                   
	                    if(data[i].checkStatus == "0"){
	                    	 html += '<p>审核时间<span></span></p>';
	                    	html += '<p>审核状态<span>未审核</span></p></div>';
	                    }else if(data[i].checkStatus == "1"){
	                    	 html += '<p>审核时间<span>'+data[i].checkTime+'</span></p>';
	                    	html += '<p>审核状态<span>已通过</span></p></div>';
	                    }else if(data[i].checkStatus == "2"){
	                    	 html += '<p>审核时间<span>'+data[i].checkTime+'</span></p>';
	                    	html += '<p>审核状态<span>不通过</span></p></div>';
	                    }
					}
					$(".modal_list").append(html);
				}else{
					$(".load_more").html("暂无更多记录");
				}
			},
			error:function (XMLHttpRequest, textStatus, errorThrown) { 
				alert("请求失败："+XMLHttpRequest.status);    
			}
		});
	}
	
	mentionMoney_list(page);
	
	$(".load_more").on("click",function(){
		page++;
		mentionMoney_list(page,1);
	})
})